

function showSub(ul, div){
    $(".sudList").hide();
    $("#" + ul).show();
    $("#" + div).removeClass('odd');
}

function getPaginatedListProducts(url, div){
	$('#itensPage').val($('#itens').val());
    $('#orderBy').val($('#order').val());
    var itensPage = $('#itensPage').val();
    var orderBy = $('#orderBy').val();
    var enterprise = $('#enterprise').val();
    var category = $('#category').val();
    var search = $('#filter').val();
    if (category != null && category != "") {
        url = url + '/category/' + category;
    }
    
    if (enterprise != null && enterprise != "") {
    	 url = url + '/title/' + enterprise
    }
    
    if (search != null && search != "") {
    	 url = url + '/search/' + search
    }
    if(itensPage != null && itensPage != ""){
    	url = url + '/itensPage/' + itensPage;
    }
    
    if(orderBy != null && orderBy != ""){
    	url = url + '/orderBy/' + orderBy;
    } 
    
    $.get(url, function(data){
        $('#' + div + '').html($(data).find('#list-products').html());
    });
}

//Carrega a lista paginada e coloca dentro da div
function getListProductsPaginated(url, div){
    
    var search = $('#search').val();
   
    if (search != null && search != "" ) {
        url = url + search;
    }
    
    
    $.get(url, function(data){
        $('#' + div + '').html($(data).find('#list-products').html());
    });
}

function addToCart(url){
    $.get(url, function(data){
        if (data == '0') {
            openPopup('#login');
            $('body').scrollTop(0);
        }
        else {
        	
        	$.get("/products", function(data){
                $('#my_shopping').html($(data).find('#my_shopping').html());
            });
        	
            openPopup('#carrinho');
            $('body').scrollTop(0);
        }
    });
}

function alterQtd(url, id){

    var qtd = $('#qtd' + id).val();
    
    url = url + qtd;
    
    $.get(url, function(data){
        showCart('/cart/show-cart', 'list-carrinho');
    });
    
}

function showCart(url, div){
    $.get(url, function(data){
        if (data == '0') {
            openPopup('#login');
        }
        else {
            $('#' + div + '').html($(data).find('#envolve').html());
        }
    });
}

function showEdit(url, div){
    $.get(url, function(data){
        if (data == '0') {
            openPopup('#login');
            $('body').scrollTop(0);
        }
        else {
            $('#' + div + '').html($(data).find('#edit-envolve').html());
        }
    });
}

function deleteItem(url){
    $.get(url, function(data){
        showCart('/cart/show-cart', 'list-carrinho');
        
        $.get("/products", function(data){
            $('#my_shopping').html($(data).find('#my_shopping').html());
        });
    });
}

function getPaginatedTransaction(url, div){
   $.get(url, function(data){
       $('#list-transactions').html($(data).find('#list-transactions').html());
   });
}